package api;


import java.util.Calendar;
import java.util.Date;

public class Test2 {
    public static void main(String[] args) {
        //创建日期对象，把当前时间输出
        System.out.println(new Date());
        // 创建日期对象，把当前的毫秒值转成日期对象
        System.out.println(new Date(0L));

        //创建时间对象
        Date date = new Date();
//        long time = 1000*60*60;
        long time = System.currentTimeMillis();
        date.setTime(time);

        System.out.println(date);
        CalendarTest();
    }

    public static void CalendarTest(){
        Calendar instance = Calendar.getInstance();
        System.out.println(instance);
        int year = instance.get(Calendar.YEAR);
        int month = instance.get(Calendar.MONTH)+1;
        int day = instance.get(Calendar.DAY_OF_MONTH);

        int hour = instance.get(Calendar.HOUR);
        int minute = instance.get(Calendar.MINUTE);
        int second = instance.get(Calendar.SECOND);
        int week = instance.get(Calendar.DAY_OF_WEEK);//返回值范围：1--7，分别表示："星期日","星期一","星期二",...,"星期六"

        System.out.println(year + "年" + month + "月" + day + "日" +
                hour + ":" + minute + ":" + second);
        System.out.println(getWeek(week));
    }

    //查表法，查询星期几
    public static String getWeek(int w) {//w = 1 --- 7
        //做一个表(数组)
        String[] weekArray = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
        //            索引      [0]      [1]       [2]      [3]       [4]      [5]      [6]
        //查表
        return weekArray[w - 1];
    }

}
